<template>
  <div style="background: #e8f1f8">
    <div class="det_tab">
      <div class="det_tab_item">
        <div style="margin-bottom: 10px">记录详情</div>
        <van-cell-group :border="border">
          <van-field
            label="检查人"
            class="input_text"
            :value="form.CreateChnName"
            readonly
          />
          <van-field
            label="检查日期"
            class="input_text"
            :value="form.CreateDate"
            readonly
          />
          <van-field
            label="最新状态"
            class="input_text"
            :value="form.StatusName"
            readonly
          />
          <van-field
            label="来源"
            class="input_text"
            :value="
              form.OriginType == 1
                ? '检查表检查'
                : form.StatusName == 2
                ? '依据检查'
                : '随手拍'
            "
            readonly
          />
          <van-field
            v-if="form.OriginType == 1"
            label="检查内容"
            class="input_text"
            rows="1"
            autosize
            type="textarea"
            :value="form.DetailItemName"
            readonly
          />
          <van-field
            label="检查结果"
            class="input_text"
            :value="
              form.CheckResult == 'N'
                ? '不符合'
                : form.CheckResult == 'NA'
                ? '不适用'
                : '符合'
            "
            readonly
          />

          <template v-if="form.CheckResult == 'N'">
            <van-field class="input_text" name="Attachs" label="隐患图片">
              <template #input>
                <image-preview :images="form.Attachs"></image-preview>
              </template>
            </van-field>
            <van-field
              label="隐患区域"
              class="input_text"
              :value="form.HiddenDangerArea"
              readonly
            />
            <van-field
              label="隐患描述"
              class="input_text"
              :value="form.HiddenDangerDesc"
              readonly
            />
            <van-field
              label="隐患分类"
              class="input_text"
              :value="
                form.LGDType == 1
                  ? '基础管理' + '>' + form.LGDName
                  : '现场管理' + '>' + form.LGDName
              "
              readonly
            />
            <van-field
              v-if="form.GistSource"
              label="依据来源"
              class="input_text"
              :value="form.GistSource"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
            <van-field
              label="整改建议"
              class="input_text"
              rows="1"
              autosize
              type="textarea"
              :value="form.CorrectiveAdvise || '无'"
              readonly
            />

            <!-- <van-field
              v-if="form.Status >= 30"
              label="整改部门"
              class="input_text"
              :value="form.CorrectiveDeptName"
              readonly
            /> -->
            <van-field
              v-if="form.PlanCorrectiveDate"
              label="计划整改期限"
              class="input_text"
              :value="form.PlanCorrectiveDate"
              readonly
            />
            <van-field
              v-if="form.CorrectiveChnName"
              label="整改人"
              class="input_text"
              :value="form.CorrectiveChnName"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.Analysis"
              label="原因分析"
              class="input_text"
              :value="form.Analysis"
              readonly
            />
            <van-field
              v-if="form.Status >= 45"
              label="整改方式"
              class="input_text"
              :value="form.CorrectiveMethod == 1 ? '立即整改' : '限期整改'"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.CorrectiveMethod == 2"
              label="整改期限"
              class="input_text"
              :value="form.CorrectiveDate"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.CorrectiveMethod == 2"
              label="整改措施"
              class="input_text"
              :value="form.CorrectiveMeasure"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.Expenses"
              label="经费"
              class="input_text"
              :value="form.Expenses"
              readonly
            />
            <van-field
              v-if="form.Status >= 60"
              label="整改图片"
              class="input_text"
              :value="form.StatusName"
              readonly
            >
              <template #input>
                <image-preview :images="form.CorrectiveAttachs"></image-preview>
              </template>
            </van-field>
            <van-field
              v-if="form.Status >= 60"
              label="整改说明"
              class="input_text"
              :value="form.CorrectiveDesc"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
          </template>
          <template v-else>
            <van-field
              class="input_text"
              label="备注"
              :value="form.Remarks"
              readonly
            />
          </template>
        </van-cell-group>
      </div>
      <div class="det_tab_item" style="margin-top: 10px">
        <div class="operate_det">
          <div style="margin-bottom: 10px">操作历史记录</div>
          <div class="operate_list">
            <van-row class="operate_row_first">
              <van-col span="4">序号</van-col>
              <van-col offset="1" span="10">操作</van-col>
            </van-row>
            <van-row
              v-for="(item, index) in form.LogList"
              :key="index"
              class="operate_row"
            >
              <van-col span="4">{{ index + 1 }}</van-col>
              <van-col offset="1" span="18"
                >{{ item.OperateLog }}
                <div v-if="item.Attachs">
                  <image-preview :images="item.Attachs"></image-preview>
                </div>
              </van-col>
            </van-row>
          </div>
        </div>
      </div>
      <div class="det_tab_item" style="margin-top: 10px" v-if="form.Status==50">
        <div class="operate_det">
          <div style="margin-bottom: 10px">整改操作</div>
          <van-field class="input_text" name="uploader" label="整改图片" required>
            <template #input>
              <image-uploader :images.sync="editForm.CorrectiveAttachs"></image-uploader>
            </template>
          </van-field>
          <van-field
            v-model="editForm.CorrectiveDesc"
            rows="3"
            required
            autosize
            label="整改说明"
            type="textarea"
            placeholder="请输入整改说明"
          />
        </div>
        <div style="margin: 16px">
          <van-button round block type="info" @click="submit">提交</van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getDangerDetail } from "@/api/dangerCheckTaskDetail";
import { jgConfirmCorrective } from "@/api/OtherdangerCheckTaskDetailJG";
import { upload } from "@/api/common";
import { deepClone } from "@/utils";
import ImageUploader from '../../../components/ImageUploader.vue';
export default {
  components: {ImageUploader},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      border: false,
      active: "a",
      reason: false,
      expenses: false,
      showCalendar: false,
      CorrectiveUserName: "",
      CorrectiveChnName: "",
      form: {},
      imgs: [],
      editForm: {},
      remarks: "",
      fileList: [],
      radio: "1",
      tabList: [
        { title: "人员信息", name: "a" },
        { title: "风险告知信息", name: "b" },
        { title: "操作规程", name: "c" },
        { title: "应急处置卡", name: "d" },
        { title: "隐患排查", name: "e" },
        { title: "设备信息", name: "f" },
        { title: "化学品信息", name: "g" },
        { title: "事故记录", name: "h" },
      ],
    };
  },
  filters: {
    formatDate: function (value, args) {
      var dt = new Date(value);
      var y = dt.getFullYear();
      var m = dt.getMonth() + 1;
      var d = dt.getDate();
      if (args.toLowerCase() === "yyy-mm-dd") {
        return `${y}-${m}-${d}`;
      } else {
        var hh = dt.getHours();
        var mm = dt.getMinutes();
        var ss = dt.getSeconds();
        return `${y}-${m}-${d}:${hh}:${mm}:${ss}`;
      }
    },
  },
  created() {
    this.geDetail();
  },
  activated() {
    if (this.$route.params.Operator) {
      this.CorrectiveUserName = this.$route.params.Operator;
      this.CorrectiveChnName = this.$route.params.OperatorName;
    }
  },
  methods: {
    onOversize(file) {
      Toast("文件大小不能超过 2M");
    },
    afterRead(file) {
      let params = new FormData(); //创建form对象
      params.append("file", file.file);
      upload(params)
        .then((res) => {
          res.data.forEach((item) => {
            this.imgs.push(item.FilePath);
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    // 获取详情
    geDetail() {
      getDangerDetail({ id: this.id }).then((res) => {
        this.form = res.data;
        this.editForm = deepClone(res.data);
      });
    },
    submit() {
      let param = {
        ID: this.editForm.ID,
        CorrectiveDesc: this.editForm.CorrectiveDesc,
        CorrectiveAttachs: this.imgs.join(";"),
      };
      jgConfirmCorrective(param)
        .then((res) => {
          this.$toast("保存成功");
          // this.loading = false
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}
.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    font-size: 12px;
    border: 1px solid #e8f1f8;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      line-height: 16px;
    }
  }
}
</style>
